""" java libraries """
from java.awt import Color
from java.awt import Font
from java.util import Locale
from java.io import File
from java.text import DecimalFormat
from java.lang import String
from java.lang import Double
from java.lang import Math
""" jhplot libraries """
from jhplot.jadraw import JaText
from jhplot.jadraw import JaKey
from jhplot  import HPlotJa
from jhplot  import H1D
from jhplot  import F1D
from jhplot  import P1D
""" jscinttools libraries """
from jscinttools.scint import SetupFileReader
from jscinttools.utilities.scintutilities import ScintUtil
from jscinttools.utilities.aidautilities import AidaFileReader
from jscinttools.utilities.aidautilities import AUtil
from jscinttools.utilities.aidautilities import AidaFactories
from jscinttools.utilities.plotterutilities import BeautifierFactory
from jscinttools.utilities.plotterutilities import PlotFonts
from jscinttools.utilities.plotterutilities import PlotColors
from jscinttools.utilities.plotterutilities import FileExtensions
from jscinttools.scint.emissionspectrum import EmSpecCorrCalculator

Locale.setDefault(Locale.ENGLISH) #For French OS

showFigures = True
writeFigures = not showFigures
drawPrelim = True
showZoom = False
showStatBox = False

genPath = "/home/marc-antoine/Documents/ZnWO4/Run_9/Reduced/TDC"
aidaName = "Run_9_QF"

afrR9 = AidaFileReader(genPath, aidaName)
tempName = ["300", "250", "200", "160", "100", "77", "50", "40", "30", "20", "15", "10", "8", "6", "5", "4", "3400m"]
tempNameTitle = ["300", "250", "200", "160", "100", "77", "50", "40", "30", "20", "15", "10", "8", "6", "5", "4", "3.4"]

afrEmSpec = AidaFileReader("/home/marc-antoine/Documents/ZnWO4/Emission_Spectra", "ZnWO4_EmissionSpectra")
emSpecDPS = afrEmSpec.grabDPS("30eV_Hasylab/corrFacNorm")
emSpecCorrCalc = EmSpecCorrCalculator(emSpecDPS)

prelim = JaText("PRELIMINARY", 0.05, 0.35, "NDC")
prelim.setFont(PlotFonts.SF_B_30)
prelim.setColor(Color.RED)
prelim.setRotAngle(-45)

peaks = ["GammaPeak", "AlphaPeak"]
peak = ["Gamma", "Alpha"]
source = ["^{137}Cs &gamma;-", "^{241}Am &gamma;-"]

fmt = DecimalFormat("#.##")
fmtSc = DecimalFormat("0.00E0")

specTup = afrR9.grabTuple("Spectra/SpecFit")
specTup.start()
specTupCol = specTup.columns()

gPulseTup = afrR9.grabTuple("GammaPeak/gammaPulseFit")
gPulseTup.start()
gPulseTupCol = gPulseTup.columns()

aPulseTup = afrR9.grabTuple("AlphaPeak/alphaPulseFit")
aPulseTup.start()
aPulseTupCol = aPulseTup.columns()
for i in range(len(tempName)):
	specTup.next()
	fitResValF = []
	fitResValErrF = []
	fitResStr = []
	
	for j in range((specTupCol - 2.0) / 2.0):
		fitResValF.append(fmt.format(specTup.getDouble((j * 2) + 1)))
		fitResValErrF.append(fmt.format(specTup.getDouble((j * 2)  + 2)))
		fitResStr.append(fitResValF[j] + " &plusmn; " + fitResValErrF[j])
	chi2ValF = fmt.format(specTup.getDouble(specTupCol - 1))
	
	statLine = []
	statLine.append("Amp = " + fitResStr[0])
	statLine.append("&micro; = " + fitResStr[1])
	statLine.append("&sigma; = " + fitResStr[2])
	statBox = [] #Some Fit Results
	for j in range (len(statLine)):
		statBox.append(JaText(statLine[j], 0.6, 0.375 + (j * 0.035), "NDC"))
		statBox[j].setFont(PlotFonts.STATBOX_FONT)
		statBox[j].setColor(Color.BLACK)
		
	statLine2 = []
	statLine2.append("Amp = " + fitResStr[3])
	statLine2.append("&micro; = " + fitResStr[4])
	statLine2.append("&sigma; = " + fitResStr[5])
	statBox2 = [] #Some Other Fit Results
	for j in range (len(statLine2)):
		statBox2.append(JaText(statLine2[j], 0.35, 0.5 + (j * 0.035), "NDC"))
		statBox2[j].setFont(PlotFonts.STATBOX_FONT)
		statBox2[j].setColor(Color.BLACK)
	
	specHisto = afrR9.grabHisto1D("Spectra/" + tempName[i] + "K")
	
	specTitle = "ZnWO_{4}, Spectrum at T = " + tempNameTitle[i] + " K"
	spec = H1D(specHisto)
	spec.setTitle(specTitle)
	spec.setColor(Color.BLUE)
	spec.setStyle("h")
	spec.setPenWidth(2)
	spec.setErrAll(False)
	
	xMin = spec.getMin()
	xMax = spec.getMax()
	
	specIFunc = afrR9.grabFunction("Spectra/FitFunc_" + tempName[i] + "K")
	specFunc = F1D(specIFunc, xMin, xMax)
	specFunc.setTitle(specTitle)
	specFunc.setMin(10000)
	specFunc.setColor(Color.RED)
	specFunc.setPenWidth(2)
	specFunc.setMin(0)
	specFunc.setMax(400)
	
	yMax = 0
	maxBin = specHisto.maxBinHeight()  + 0.5
	ceilMaxBin = Math.ceil(maxBin)
	if ((ceilMaxBin - maxBin) > 0.5):
		yMax = ceilMaxBin - 0.5
	else:
		yMax = ceilMaxBin
	specPlotter = HPlotJa(specTitle, 600, 600, 1, 1, True)
	specPlotter.setGTitle(specTitle, PlotFonts.TITLE_FONT)
	specPlotter.setAntiAlias(False)
	specPlotter.visible(showFigures)
	specPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
	specPlotter.setRange(0, 400, 0, yMax)
	specPlotter.setTicFont(PlotFonts.TICK_FONT)
	specPlotter.setShowStatBox(False)
	specPlotter.showKey(False)
	specPlotter.setNameX("Number of Photons")
	specPlotter.setNameY("Counts (a.u.)")
	specPlotter.draw(spec)
	specPlotter.draw(specFunc)
	specPlotter.draw(prelim)
	for j in range (len(statLine)):
		specPlotter.draw(statBox[j])
	for j in range (len(statLine2)):
		specPlotter.draw(statBox2[j])
	specPlotter.update()
	
	pbSpec = BeautifierFactory.beautifyHPlotJa(specPlotter)
	specPad11 = pbSpec.pad(1, 1)
	specLabelX11 = specPad11.axisLabel(0)
	specLabelX11.centerLabel(0.0)
	specLabelX11.changeFont(PlotFonts.AXIS_LABEL_FONT)
	specLabelY11 = specPad11.axisLabel(1)
	specLabelY11.centerLabel(-0.00)
	specLabelY11.changeFont(PlotFonts.AXIS_LABEL_FONT)
	
	specTickLabX11 = specPad11.tickLabel(0)
	specTickLabX11.axisDistance(0.0)
	specTickLabX11.removeNegativeZero()
	specTickLabY11 = specPad11.tickLabel(1)
	specTickLabY11.axisDistance(-0.00)
	specTickLabY11.removeNegativeZero()
	
	specPlotter.update()
	if writeFigures:
		for j in range(len(FileExtensions.FIG_TYPES)):
			outFileName = "ZnWO4_Spectrum_" + tempName[i] + "K" + FileExtensions.FIG_TYPES[j]
			specPlotter.export(genPath + File.separator + outFileName)
			print("Writting File : " + genPath + File.separator + outFileName)
	
	for j in range(len(peaks)):
		avEvtHist = None
		iFunc = None
		amp = []
		ampErr = []
		tau = []
		tauErr = []
		p0 = 0
		p0Err = 0
		chi2 = 0
		if (peaks[j] == "GammaPeak"):
			avEvtHist = afrR9.grabHisto1D("GammaPeak/AvPulse_" + tempName[i] + "K")
			iFunc = afrR9.grabFunction("GammaPeak/AvEvt_" + tempName[i] + "K")
			gPulseTup.next()
			print (gPulseTupCol - 4.0) / 4.0
			for k in range((gPulseTupCol - 4.0) / 4.0):	
				amp.append(gPulseTup.getDouble((k * 4) + 1))
				ampErr.append(gPulseTup.getDouble((k * 4) + 2))
				tau.append(gPulseTup.getDouble((k * 4) + 3))
				tauErr.append(gPulseTup.getDouble((k * 4) + 4))
				p0 = gPulseTup.getDouble(gPulseTupCol - 3)
				p0Err = gPulseTup.getDouble(gPulseTupCol - 2)
				chi2 = gPulseTup.getDouble(gPulseTupCol - 1)

		elif (peaks[j] == "AlphaPeak"):
			avEvtHist = afrR9.grabHisto1D("AlphaPeak/AvPulse_" + tempName[i] + "K")
			iFunc = afrR9.grabFunction("AlphaPeak/AvEvt_" + tempName[i] + "K")
			aPulseTup.next()
			for k in range((aPulseTupCol - 4.0) / 4.0):	
				amp.append(aPulseTup.getDouble((k * 4) + 1))
				ampErr.append(aPulseTup.getDouble((k * 4) + 2))
				tau.append(aPulseTup.getDouble((k * 4) + 3))
				tauErr.append(aPulseTup.getDouble((k * 4) + 4))
				p0 = gPulseTup.getDouble(gPulseTupCol - 3)
				p0Err = gPulseTup.getDouble(gPulseTupCol - 2)
				chi2 = gPulseTup.getDouble(gPulseTupCol - 1)
		
				
		fnLY = []
		fnLYErr = []
		fitResValF = []
		fitResValErrF = []
		fitResStr = []
		for k in range(len(tau)):
			fnLY.append(ScintUtil.calcLYFrac(k, amp, tau))
			fnLYErr.append(ScintUtil.calcLYFracErr(k, amp, ampErr, tau, tauErr))		
			fitResValF.append(fmt.format(fnLY[k]))
			fitResValF.append(fmt.format(tau[k]))
			fitResValErrF.append(fmt.format(fnLYErr[k]))
			fitResValErrF.append(fmt.format(tauErr[k]))
		fitResValF.append(fmt.format(p0))
		fitResValErrF.append(fmt.format(p0Err))
		
		for k in range(len(fitResValF)):
			fitResStr.append(fitResValF[k] + " &plusmn; " + fitResValErrF[k])
		chi2ValF = fmt.format(chi2)
		
		statLine = []
		statLine.append("fn_{0} = " + fitResStr[0])
		statLine.append("&tau;_{0} = " + fitResStr[1] + " &micro;s")
		statLine.append("fn_{1} = " + fitResStr[2])
		statLine.append("&tau;_{1} = " + fitResStr[3] + " &micro;s")
		statLine.append("fn_{2} = " + fitResStr[4])
		statLine.append("&tau;_{2} = " + fitResStr[5] + " &micro;s")
		statLine.append("P_{0} = " + fitResStr[6])
		statLine.append("&chi;^{2} = " + chi2ValF)
		
		statBox = [] #Some Fit Results
		for k in range (len(statLine)):
			statBox.append(JaText(statLine[k], 0.175, 0.575 + (k * 0.035), "NDC"))
			statBox[k].setFont(PlotFonts.STATBOX_FONT)
			statBox[k].setColor(Color.BLACK)
		
		avEvt = H1D(avEvtHist)	
		avEvt.setTitle("ZnWO_{4} " + source[j] + "Peak, Pulse at T = " + tempNameTitle[i] + " K")
		avEvt.setColor(Color.BLUE)
		avEvt.setStyle("h")
		avEvt.setPenWidth(2)
		avEvt.setErrAll(False)

		#win = sfrPeak.findParamValues("Av Pulse Window (Xmin, Xmax, Ymin, Ymax)")
		#winZoom = sfrPeak.findParamValues("Av Pulse Zoom Window (Xmin, Xmax, Ymin, Ymax)")
		win = [0, avEvt.getMax(), 0.00001, 1]
		winZoom = [0, 0.5, 0.1, 1]
		
		func = F1D(iFunc)
		func.setTitle(avEvt.getTitle())
		func.setMin(10000)
		func.setColor(Color.RED)
		func.setPenWidth(2)
		func.setMin(win[0])
		func.setMax(win[1])
		
		funcZoom = F1D(iFunc)
		funcZoom.setTitle(avEvt.getTitle())
		funcZoom.setMin(10000)
		funcZoom.setColor(Color.RED)
		funcZoom.setPenWidth(2)
		funcZoom.setMin(winZoom[0])
		funcZoom.setMax(winZoom[1])
		
		title = avEvt.getTitle()
		plotter = None
		if showZoom:
			plotter = HPlotJa(title, 600, 600, 2, 1, True)
		else: 
			plotter = HPlotJa(title, 600, 600, 1, 1, True)
		plotter.setGTitle(title, PlotFonts.TITLE_FONT)
		plotter.setAntiAlias(False)
		plotter.visible(showFigures)
		
		plotter.cd(1,1)	
		plotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
		plotter.setRange(win[0], win[1], win[2], win[3])
		plotter.setLogScale(0, False)
		plotter.setLogScale(1, True)
		plotter.setTicFont(PlotFonts.TICK_FONT)
		plotter.setShowStatBox(False)
		plotter.showKey(False)
		plotter.setNameX("Time (&micro;s)")
		plotter.setNameY("Photons / Time Unit")
		
		if showZoom:
			plotter.cd(2,1)	
			plotter.setPad(2, 1, 0.525, 0.17, 0.3, 0.3)
			plotter.setRange(winZoom[0], winZoom[1], winZoom[2], winZoom[3])
			plotter.setLogScale(0, False)
			plotter.setLogScale(1, True)
			plotter.setTicFont(PlotFonts.TICK_FONT)
			plotter.setShowStatBox(False)
			plotter.showKey(False)
			plotter.setNameX("")
			plotter.setNameY("")
		
		""" Plots all the JHep objects"""
		plotter.cd(1,1)
		plotter.draw(avEvt)
		plotter.draw(func)
		plotter.draw(prelim)
		if showStatBox:
			for k in range (len(statLine)):
				plotter.draw(statBox[k])
		
		if showZoom:
			plotter.cd(2,1)
			plotter.draw(avEvt)
			plotter.draw(funcZoom)
		
		plotter.update()
		
		pb = BeautifierFactory.beautifyHPlotJa(plotter)
		pad11 = pb.pad(1, 1)
		labelX11 = pad11.axisLabel(0)
		labelX11.centerLabel(0.0)
		labelX11.changeFont(PlotFonts.AXIS_LABEL_FONT)
		labelY11 = pad11.axisLabel(1)
		labelY11.centerLabel(-0.005)
		labelY11.changeFont(PlotFonts.AXIS_LABEL_FONT)
		
		tickLabX11 = pad11.tickLabel(0)
		tickLabX11.axisDistance(0.0)
		tickLabX11.removeNegativeZero()
		tickLabY11 = pad11.tickLabel(1)
		tickLabY11.axisDistance(-0.00)
		tickLabY11.displayAsPowerOfTen()
		
		if showZoom:
			pad21 = pb.pad(2, 1)
			labelX21 = pad21.axisLabel(0)
			labelX21.centerLabel(0.0)
			labelX21.changeFont(PlotFonts.AXIS_LABEL_FONT)
			labelY21 = pad21.axisLabel(1)
			labelY21.centerLabel(-0.01)
			labelY21.changeFont(PlotFonts.AXIS_LABEL_FONT)
			
			tickLabX21 = pad21.tickLabel(0)
			tickLabX21.axisDistance(0.0)
			tickLabX21.removeNegativeZero()
			tickLabX21.displayAsDecimal("0.0")
			tickLabY21 = pad21.tickLabel(1)
			tickLabY21.axisDistance(-0.01)
			tickLabY21.displayAsPowerOfTen()
        	
		plotter.update()
		if writeFigures:
			for k in range(len(FileExtensions.FIG_TYPES)):
				outFileName = "ZnWO4_AvPulse_" + peak[j] + "_" + tempName[i] + "K" + FileExtensions.FIG_TYPES[k]
				plotter.export(genPath + File.separator + outFileName)
				print("Writting File : " + genPath + File.separator + outFileName)

keyInitY = 0.35
lyGammaDPS = afrR9.grabDPS("Cs137_LY")
gammaLY = P1D(lyGammaDPS)
gammaLY.setTitle("137Cs &gamma;")
gammaLY.setColor(Color.BLUE)
gammaLY.setStyle("p")
gammaLY.setSymbol(0)
gammaLY.setSymbolSize(16)
gammaLY.setErrX(False)
gammaLYKey = JaKey(gammaLY.getSymbol(), gammaLY.getTitle(), 0.2, keyInitY + 0.1, "NDC")
gammaLYKey.setFont(PlotFonts.LEGEND_FONT)
gammaLYKey.setColor(gammaLY.getColor())
gammaLYKey.setKeyColor(gammaLY.getColor())

lyAlphaDPS = afrR9.grabDPS("Am241_LY")
alphaLY = P1D(lyAlphaDPS)
alphaLY.setTitle("241Am &alpha;")
alphaLY.setColor(Color.RED)
alphaLY.setStyle("p")
alphaLY.setSymbol(2)
alphaLY.setSymbolSize(16)
alphaLY.setErrX(False)
alphaLYKey = JaKey(alphaLY.getSymbol(), alphaLY.getTitle(), 0.2, keyInitY + 0.05, "NDC")
alphaLYKey.setFont(PlotFonts.LEGEND_FONT)
alphaLYKey.setColor(alphaLY.getColor())
alphaLYKey.setKeyColor(alphaLY.getColor())

oxAlphaLYx = [8.0, 15.0, 30.0, 60.0, 95.0, 120.0, 150.0, 180.0, 210.0, 240.0, 270.0, 300.0]
oxAlphaLYy = [2.895, 2.895, 2.895, 2.868, 2.684, 2.421, 2.316, 2.237, 1.974, 1.632, 1.421, 1.000]
oxAlphaLYP1D = P1D("241Am &alpha; H. Kraus et al.", oxAlphaLYx, oxAlphaLYy)
oxAlphaLYP1D.setStyle("p")
oxAlphaLYP1D.setColor(Color.BLACK)
oxAlphaLYP1D.setSymbol(3)
oxAlphaLYP1D.setSymbolSize(16)
oxAlphaLYP1D.setErrAll(False)
oxAlphaLYP1DKey = JaKey(oxAlphaLYP1D.getSymbol(), oxAlphaLYP1D.getTitle(), 0.2, keyInitY, "NDC")
oxAlphaLYP1DKey.setFont(PlotFonts.LEGEND_FONT)
oxAlphaLYP1DKey.setColor(oxAlphaLYP1D.getColor())
oxAlphaLYP1DKey.setKeyColor(oxAlphaLYP1D.getColor())

afrRun4 = AidaFileReader("/home/marc-antoine/Documents/ZnWO4/Run_4", "ScintillationAnalysis_ZnWO4_Txt")
na22DPS = afrRun4.grabDPS("Light_Yield/LY_Corr")
sf = 1.0
for i in range(na22DPS.size()):
	pt = na22DPS.point(i)
	ptX = pt.coordinate(0)
	t = ptX.value()
	ptY = pt.coordinate(1)
	v = ptY.value()
	eMin = ptY.errorMinus()
	eMax = ptY.errorPlus()
	emSpecCorr = emSpecCorrCalc.extrapolCorrFac(t)
	print t
	print emSpecCorr
	ptY.setValue(v / emSpecCorr)
	ptY.setErrorMinus(eMin / emSpecCorr)
	ptY.setErrorPlus(eMax / emSpecCorr)
	if t == 300.0:
		sf = ptY.value()
	
#print "\n\n"
#print na22DPS.point(0).coordinate(0).value()
#print na22DPS.point(0).coordinate(1).value()
#print "\n\n"

for i in range(na22DPS.size()):
	pt = na22DPS.point(i)
	ptY = pt.coordinate(1)
	v = ptY.value()
	eMin = ptY.errorMinus()
	eMax = ptY.errorPlus()
	ptY.setValue(v / sf)
	ptY.setErrorMinus(eMin / sf)
	ptY.setErrorPlus(eMax / sf)
	
na22LY = P1D(na22DPS)
na22LY.setTitle("22Na &gamma;")
na22LY.setColor(PlotColors.DARK_GREEN)
na22LY.setStyle("p")
na22LY.setSymbol(8)
na22LY.setSymbolSize(16)
na22LY.setErrX(False)
na22LYKey = JaKey(na22LY.getSymbol(), na22LY.getTitle(), 0.2, keyInitY + 0.15, "NDC")
na22LYKey.setFont(PlotFonts.LEGEND_FONT)
na22LYKey.setColor(na22LY.getColor())
na22LYKey.setKeyColor(na22LY.getColor())

lyPlotter = HPlotJa("ZnWO4 LY", 600, 600, 1, 1, True)
lyPlotter.setGTitle("LY of ZnWO_{4}", PlotFonts.TITLE_FONT)
lyPlotter.setAntiAlias(False)
lyPlotter.visible(showFigures)
lyPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
lyPlotter.setRange(1, 1000, 0.75, 3.25)
lyPlotter.setLogScale(0, True)
lyPlotter.setTicFont(PlotFonts.TICK_FONT)
lyPlotter.setShowStatBox(False)
lyPlotter.showKey(False)
lyPlotter.setNameX("Temperature (K)")
lyPlotter.setNameY("LY normalized to 300 K")
lyPlotter.draw(oxAlphaLYP1D)
#lyPlotter.draw(na22LY)
lyPlotter.draw(gammaLY)
lyPlotter.draw(alphaLY)
lyPlotter.draw(oxAlphaLYP1DKey)
#lyPlotter.draw(na22LYKey)
lyPlotter.draw(gammaLYKey)
lyPlotter.draw(alphaLYKey)
lyPlotter.draw(prelim)
lyPlotter.update()

pbLY = BeautifierFactory.beautifyHPlotJa(lyPlotter)
lyPad11 = pbLY.pad(1, 1)
lyLabelX11 = lyPad11.axisLabel(0)
lyLabelX11.centerLabel(0.0)
lyLabelX11.changeFont(PlotFonts.AXIS_LABEL_FONT)
lyLabelY11 = lyPad11.axisLabel(1)
lyLabelY11.centerLabel(-0.005)
lyLabelY11.changeFont(PlotFonts.AXIS_LABEL_FONT)

lyTickLabX11 = lyPad11.tickLabel(0)
lyTickLabX11.axisDistance(0.0)
lyTickLabX11.displayAsPowerOfTen()
lyTickLabY11 = lyPad11.tickLabel(1)
lyTickLabY11.axisDistance(-0.00)
lyTickLabY11.removeNegativeZero()

lyPlotter.update()
if writeFigures:
	for j in range(len(FileExtensions.FIG_TYPES)):
		outFileName = "ZnWO4_LY" + FileExtensions.FIG_TYPES[j]
		lyPlotter.export(genPath + File.separator + outFileName)
		print("Writting File : " + genPath + File.separator + outFileName)

qfDPS = afrR9.grabDPS("agQF")
agQF = P1D(qfDPS)
agQF.setTitle("&alpha;/&gamma; Quenching Factor")
agQF.setColor(Color.BLUE)
agQF.setStyle("p")
agQF.setSymbol(0)
agQF.setSymbolSize(10)
agQF.setErrX(False)
agQFKey = JaKey(agQF.getSymbol(), agQF.getTitle(), 0.5, 0.2, "NDC")
agQFKey.setFont(PlotFonts.LEGEND_FONT)
agQFKey.setColor(agQF.getColor())
agQFKey.setKeyColor(agQF.getColor())

qfPlotter = HPlotJa("ZnWO4 &alpha;/&gamma; Quenching Factor", 600, 600, 1, 1, True)
qfPlotter.setGTitle("ZnWO_{4} &alpha;/&gamma; Quenching Factor", PlotFonts.TITLE_FONT)
qfPlotter.setAntiAlias(False)
qfPlotter.visible(showFigures)
qfPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
qfPlotter.setRange(1, 1000, 0.17, 0.21)
qfPlotter.setLogScale(0, True)
qfPlotter.setTicFont(PlotFonts.TICK_FONT)
qfPlotter.setShowStatBox(False)
qfPlotter.showKey(False)
qfPlotter.setNameX("Temperature (K)")
qfPlotter.setNameY("&alpha;/&gamma; Quenching Factor")
qfPlotter.draw(agQF)
qfPlotter.draw(prelim)
qfPlotter.update()

pbQF = BeautifierFactory.beautifyHPlotJa(qfPlotter)
qfPad11 = pbQF.pad(1, 1)
qfLabelX11 = qfPad11.axisLabel(0)
qfLabelX11.centerLabel(0.0)
qfLabelX11.changeFont(PlotFonts.AXIS_LABEL_FONT)
qfLabelY11 = qfPad11.axisLabel(1)
qfLabelY11.centerLabel(-0.005)
qfLabelY11.changeFont(PlotFonts.AXIS_LABEL_FONT)

qfTickLabX11 = qfPad11.tickLabel(0)
qfTickLabX11.axisDistance(0.0)
qfTickLabX11.displayAsPowerOfTen()
qfTickLabY11 = qfPad11.tickLabel(1)
qfTickLabY11.axisDistance(-0.00)
qfTickLabY11.removeNegativeZero()

qfPlotter.update()
if writeFigures:
	for j in range(len(FileExtensions.FIG_TYPES)):
		outFileName = "ZnWO4_agQF" + FileExtensions.FIG_TYPES[j]
		qfPlotter.export(genPath + File.separator + outFileName)
		print("Writting File : " + genPath + File.separator + outFileName)
		
qfNormDPS = afrR9.grabDPS("agQFNorm")
agQFNorm = P1D(qfNormDPS)
agQFNorm.setTitle("&alpha;/&gamma; Quenching Factor")
agQFNorm.setColor(Color.BLUE)
agQFNorm.setStyle("p")
agQFNorm.setSymbol(0)
agQFNorm.setSymbolSize(10)
agQFNorm.setErrX(False)
agQFNormKey = JaKey(agQF.getSymbol(), agQFNorm.getTitle(), 0.5, 0.2, "NDC")
agQFNormKey.setFont(PlotFonts.LEGEND_FONT)
agQFNormKey.setColor(agQFNorm.getColor())
agQFNormKey.setKeyColor(agQFNorm.getColor())

qfNormPlotter = HPlotJa("ZnWO4 &alpha;/&gamma; Peak Ratio", 600, 600, 1, 1, True)
qfNormPlotter.setGTitle("ZnWO_{4} &alpha;/&gamma; Peak Ratio", PlotFonts.TITLE_FONT)
qfNormPlotter.setAntiAlias(False)
qfNormPlotter.visible(showFigures)
qfNormPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
qfNormPlotter.setRange(1, 1000, 0.9, 1.2)
qfNormPlotter.setLogScale(0, True)
qfNormPlotter.setTicFont(PlotFonts.TICK_FONT)
qfNormPlotter.setShowStatBox(False)
qfNormPlotter.showKey(False)
qfNormPlotter.setNameX("Temperature (K)")
qfNormPlotter.setNameY("Norm &alpha;/&gamma; Peak Ratio")
qfNormPlotter.draw(agQFNorm)
qfNormPlotter.draw(prelim)
qfNormPlotter.update()

pbQFNorm = BeautifierFactory.beautifyHPlotJa(qfNormPlotter)
qfNormPad11 = pbQFNorm.pad(1, 1)
qfNormLabelX11 = qfNormPad11.axisLabel(0)
qfNormLabelX11.centerLabel(0.0)
qfNormLabelX11.changeFont(PlotFonts.AXIS_LABEL_FONT)
qfNormLabelY11 = qfNormPad11.axisLabel(1)
qfNormLabelY11.centerLabel(-0.005)
qfNormLabelY11.changeFont(PlotFonts.AXIS_LABEL_FONT)

qfNormTickLabX11 = qfNormPad11.tickLabel(0)
qfNormTickLabX11.axisDistance(0.0)
qfNormTickLabX11.displayAsPowerOfTen()
qfNormTickLabY11 = qfNormPad11.tickLabel(1)
qfNormTickLabY11.axisDistance(-0.00)
qfNormTickLabY11.removeNegativeZero()

qfNormPlotter.update()
if writeFigures:
	for j in range(len(FileExtensions.FIG_TYPES)):
		outFileName = "ZnWO4_agQFNorm" + FileExtensions.FIG_TYPES[j]
		qfNormPlotter.export(genPath + File.separator + outFileName)
		print("Writting File : " + genPath + File.separator + outFileName)

kinGammaDPS = afrR9.grabDPS("Cs137_Kin")
kinGamma = P1D(kinGammaDPS)
kinGamma.setTitle("137Cs &gamma;")
kinGamma.setColor(Color.BLUE)
kinGamma.setStyle("p")
kinGamma.setSymbol(0)
kinGamma.setSymbolSize(16)
kinGamma.setErrX(False)
kinGammaKey = JaKey(kinGamma.getSymbol(), kinGamma.getTitle(), 0.35, 0.25, "NDC")
kinGammaKey.setFont(PlotFonts.LEGEND_FONT)
kinGammaKey.setColor(kinGamma.getColor())
kinGammaKey.setKeyColor(kinGamma.getColor())

kinAlphaDPS = afrR9.grabDPS("Am241_Kin")
kinAlpha = P1D(kinAlphaDPS)
kinAlpha.setTitle("241Am &alpha;")
kinAlpha.setColor(Color.RED)
kinAlpha.setStyle("p")
kinAlpha.setSymbol(2)
kinAlpha.setSymbolSize(16)
kinAlpha.setErrX(False)
kinAlphaKey = JaKey(kinAlpha.getSymbol(), kinAlpha.getTitle(), 0.35, 0.3, "NDC")
kinAlphaKey.setFont(PlotFonts.LEGEND_FONT)
kinAlphaKey.setColor(kinAlpha.getColor())
kinAlphaKey.setKeyColor(kinAlpha.getColor())

kinNa22DPS = afrRun4.grabDPS("Kinetic/Decay_Comp#3")
kinNa22 = P1D(kinNa22DPS)
kinNa22.setTitle("22Na &gamma;")
kinNa22.setColor(PlotColors.DARK_GREEN)
kinNa22.setStyle("p")
kinNa22.setSymbol(8)
kinNa22.setSymbolSize(16)
kinNa22.setErrX(False)
kinNa22Key = JaKey(kinNa22.getSymbol(), kinNa22.getTitle(), 0.35, 0.35, "NDC")
kinNa22Key.setFont(PlotFonts.LEGEND_FONT)
kinNa22Key.setColor(kinNa22.getColor())
kinNa22Key.setKeyColor(kinNa22.getColor())

oxGamMTaux = [6.6, 7.3, 9.0, 12.2, 17.2, 24.2, 37.3, 60.0, 82.0, 110.0, 125.0, 150.0, 180.0, 215.0, 240.0, 260.0, 275.0, 280.0, 290.0, 295.0, 305.0]
oxGamMTauy = [91.4, 81.8, 63.9, 49.9, 42.6, 37.8, 35.3, 32.7, 33.3, 32.2, 32.7, 32.2, 31.1, 30.2, 30.0, 29.6, 28.5, 28.2, 27.0, 26.0, 24.5]
oxGamMTauP1D = P1D("60Co &gamma; H. Kraus et al.", oxGamMTaux, oxGamMTauy)
oxGamMTauP1D.setStyle("p")
oxGamMTauP1D.setColor(Color.BLACK)
oxGamMTauP1D.setSymbol(3)
oxGamMTauP1D.setSymbolSize(16)
oxGamMTauP1D.setErrAll(False)
oxGamMTauKey = JaKey(oxGamMTauP1D.getSymbol(), oxGamMTauP1D.getTitle(), 0.35, 0.35, "NDC")
oxGamMTauKey.setFont(PlotFonts.LEGEND_FONT)
oxGamMTauKey.setColor(oxGamMTauP1D.getColor())
oxGamMTauKey.setKeyColor(oxGamMTauP1D.getColor())

kinPlotter = HPlotJa("ZnWO4 Main Component Kinetic", 600, 600, 1, 1, True)
kinPlotter.setGTitle("ZnWO_{4} Main Component Kinetic", PlotFonts.TITLE_FONT)
kinPlotter.setAntiAlias(False)
kinPlotter.visible(showFigures)
kinPlotter.setPad(1, 1, 0.125, 0.125, 0.75, 0.75)
kinPlotter.setRange(1, 1000, 10, 1000)
kinPlotter.setLogScale(0, True)
kinPlotter.setLogScale(1, True)
kinPlotter.setTicFont(PlotFonts.TICK_FONT)
kinPlotter.setShowStatBox(False)
kinPlotter.showKey(False)
kinPlotter.setNameX("Temperature (K)")
kinPlotter.setNameY("Main Decay Time (&micro;s)")
kinPlotter.draw(kinGamma)
kinPlotter.draw(kinAlpha)
#kinPlotter.draw(kinNa22)
kinPlotter.draw(oxGamMTauP1D)
kinPlotter.draw(kinGammaKey)
kinPlotter.draw(kinAlphaKey)
#kinPlotter.draw(kinNa22Key)
kinPlotter.draw(oxGamMTauKey)
kinPlotter.draw(prelim)
kinPlotter.update()

pbKin = BeautifierFactory.beautifyHPlotJa(kinPlotter)
kinPad11 = pbKin.pad(1, 1)
kinLabelX11 = kinPad11.axisLabel(0)
kinLabelX11.centerLabel()
kinLabelX11.changeFont(PlotFonts.AXIS_LABEL_FONT)
kinLabelY11 = kinPad11.axisLabel(1)
kinLabelY11.centerLabel(-0.01)
kinLabelY11.changeFont(PlotFonts.AXIS_LABEL_FONT)

kinTickLabX11 = kinPad11.tickLabel(0)
kinTickLabX11.axisDistance(0.0)
kinTickLabX11.displayAsPowerOfTen()
kinTickLabY11 = kinPad11.tickLabel(1)
kinTickLabY11.axisDistance(-0.01)
kinTickLabY11.removeNegativeZero()

kinPlotter.update()
if writeFigures:
	for j in range(len(FileExtensions.FIG_TYPES)):
		outFileName = "ZnWO4_Kinetic" + FileExtensions.FIG_TYPES[j]
		kinPlotter.export(genPath + File.separator + outFileName)
		print("Writting File : " + genPath + File.separator + outFileName)

print "That's All Folks !!!\n"
if not showFigures:
	exit()	
